﻿@using NetSurveillance.WebApp.DataServices.Models
@model IEnumerable<VirusEmbedRule>
@{
    Layout = "~/Views/Shared/_SimpleLayout.cshtml";
    ViewBag.Title = Resources.MenuResource.MiddleMenu_VirusEmbeds;
}
@section css
{
    <style type="text/css">
        body
        {
            background-color: #ebebeb;
        }

        #tbVirusEmbed, #tbVERules
        {
            width: 100%;
            border-spacing: 0;
            border-collapse: collapse;
        }

        #tbVERules
        {
            margin-top: 30px;
            overflow: auto;
        }

            #tbVERules thead tr
            {
                height: 30px;
            }

            #tbVERules tbody tr {
                height: 30px;
            }

            #tbVERules tbody tr:hover {
                background-color: #3098ff;
                color: white;
            }

            #tbVERules tbody tr td {
                text-align: center;
            }

        #tcVERules
        {
            width: 600px;
            vertical-align: top;
            height: 480px;
            border: 1px solid gray;
        }

    #warningContain {
        line-height: 40px;
        height: 40px;    
    }
        #warningContain span
        {
            display: inline-block;
            text-indent: 10px;
            float: left;
        }
        #warningContain span:nth-child(2) {
            float: right;
        }
    </style>
}
@section javascript
{
    <script type="text/javascript">
        $(function() {
            $('#btnAddEntry').click(function() {
                window.location.href = '@Url.Action("VirusEmbedRule")';
            });
            $('#tbVERules tbody tr td:last-child a.delete').live('click', deleteEntry);
            $('#btnExit').click(windowClose);
            $('#tbVERules tbody .linkButton').live('click', function() {
                var $btn = $(this), url = $btn.attr('link');
                window.location.href = url;
                return false;
            });
            $('#btnSubmit').click(saveEntry);
        });

        function saveEntry() {
            $('#hostIds').val(JSON.stringify(getCheckHostIds()));
            return true;
        }

        function deleteEntry() {
            var $lk = $(this),
                entryId = $lk.attr('entryId');
            if (!window.confirm('@Resources.MessageResource.Delete_Confirm')) return false;
            $.ajax({
                url: '@Url.Action("Delete")',
                type: 'post',
                dataType: 'json',
                data: { veRuleId: entryId },
                success: function(result) {
                    if (result && result.success)
                        $lk.closest('tr').remove();
                    if (result && result.message)
                        alert(result.message);
                }
            });
            return false;
        }
        
        function windowClose() {
            if (!window.confirm('@Resources.MessageResource.ExitConfirm')) return;
            window.close();
        }
    </script>
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary()
    @Html.Hidden("hostIds")
    <table id="tbVirusEmbed">
        <tbody>
            <tr>
                <td style="width: 201px;" rowspan="2">
                    <div class="hostList">
                        <div class="hostListTitle">@Resources.ViewResource.HostListTitle</div>
                        <div class="hostListTree">
                            @Html.Partial("../Host/_HostTree", ViewBag.TreeNode as string)
                        </div>
                        <div class="hostListBottom">
                            <label>
                                @Html.CheckBox("isAutoMonitorHost")
                                自动监控新主机
                            </label>
                        </div>
                    </div>
                </td>
                <td id="tcVERules">
                    <table id="tbVERules">
                        <thead>
                            <tr>
                                <th colspan="3">木马植入规则
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @{ var selectedRuleIds = ViewBag.TaskVirusRuleIds as IList<long>;}
                            @foreach (var veRule in Model)
                            {
                                string indexStr = Guid.NewGuid().ToString();
                                <tr>
                                    <td>
                                        @Html.Hidden("selectRuleIds.Index", indexStr)
                                        @Html.CheckBox(string.Format("selectRuleIds[{0}]", indexStr),
                                                       veRule.Id,
                                                       selectedRuleIds != null && selectedRuleIds.Contains(veRule.Id))
                                    </td>
                                    <td>
                                        @veRule.RuleName
                                    </td>
                                    <td>
                                        <input class="linkButton" type="button" title="@string.Format("编辑{0}", veRule.RuleName)"
                                               value="@Resources.Resource.Button_Alter" link="@Url.Action("VirusEmbedRule")?veRuleId=@veRule.Id" />
                                        <a href="javascript:;" class="delete" entryId="@veRule.Id"
                                           title="@string.Format("删除{0}", veRule.RuleName)">
                                            <img src="@Url.Content("~/Content/images/showdia_trojan_X.gif")"
                                                 alt="@Resources.Resource.Button_Delete"/>
                                        </a>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </td>
                <td style="vertical-align: top; padding-top: 30px;" rowspan="2">
                    <input type="button" id="btnAddEntry" class="commonButton" value="@Resources.Resource.Button_Add" />
                </td>
            </tr>
            <tr>
                <td>
                    <div id="warningContain">
                        <span>
                            <label>
                                @Html.CheckBox("isAutoWarning")
                                监控成功报警
                            </label>
                        </span>
                        <span>
                            <label>攻击次数：</label>
                            @Html.TextBox("attackCount")
                        </span>
                        <div class="ui-helper-clearfix"></div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
    <div class="controlBottom">
        <div class="rightContain">
            <input id="btnSubmit" type="submit" class="commonButton" value="@Resources.Resource.Button_Update" />
            <input id="btnExit" type="button" class="commonButton" value="@Resources.Resource.Button_Exit"/>
        </div>
    </div>
}